import 'package:flutter/material.dart';
import 'package:flutter_shop/pages/home.dart';
import 'package:flutter_shop/pages/my.dart';
// import 'package:flutter_shop/pages/pic.dart';
import 'package:flutter_shop/pages/shopcart.dart';

// 导航栏
class Tabs extends StatefulWidget {
  const Tabs({Key? key}) : super(key: key);

  @override
  State<Tabs> createState() => _TabsState();
}

class _TabsState extends State<Tabs> {
  // 设置默认选中的下标
  int _currentIndex = 0;

  // 设置页面数组
  final List _pages = [const Home(), const Shopcart(), const My()];
  final List _title = ["首页", "购物车", "我的"];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // 顶部导航
      appBar: AppBar(
        title: Text(_title[_currentIndex]),
        backgroundColor: Colors.pink[200],
        // 阴影
        elevation: 2.0,
        // 文字居中
        centerTitle: true,
      ),
      body: _pages[_currentIndex],
      // 设置底部bar
      bottomNavigationBar: BottomNavigationBar(
        // 当前选中页
        currentIndex: _currentIndex,
        // 点击切换页事件
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
        // 设置图标颜色大小
        iconSize: 30,
        fixedColor: Colors.pink[200],
        items: const [
          // 设置导航
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
          // BottomNavigationBarItem(icon: Icon(Icons.home), label: "图片"),
          BottomNavigationBarItem(icon: Icon(Icons.shopping_cart), label: "购物车"),
          BottomNavigationBarItem(icon: Icon(Icons.people), label: "我的"),
        ],
      ),
    );
  }
}